<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>module RubyXL::RelationshipSupport - rubyXL 3.4.35</title>


  <meta name="keywords" content="ruby,module,RubyXL::RelationshipSupport">


    <meta name="description" content="module RubyXL::RelationshipSupport: +RelationshipSupport+ module enables automatic loading and saving of _rels for the respective file">





<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
</script>

<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<link href="../css/fonts.css" rel="stylesheet">
<link href="../css/rdoc.css" rel="stylesheet">



<body id="top" role="document" class="module">
<div id="navigation-toggle" role="button" tabindex="0" aria-label="Toggle sidebar" aria-expanded="true" aria-controls="navigation">
  <span aria-hidden="true">&#9776;</span>
</div>


<nav id="navigation" role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="../index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search (/) for a class, method, ..." spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  

  

  

  
<div id="extends-section" class="nav-section">
  <h3>Extended With Modules</h3>

  <ul class="link-list">


    <li><a class="extend" href="RelationshipSupport/ClassMehods.html">RubyXL::RelationshipSupport::ClassMehods</a></li>


  </ul>
</div>


  
  <div class="nav-section">
    <h3>Class Methods</h3>
    <ul class="link-list" role="directory">

      <li ><a href="#method-c-included">included</a></li>

    </ul>
  </div>



  <div class="nav-section">
    <h3>Instance Methods</h3>
    <ul class="link-list" role="directory">

      <li ><a href="#method-i-attach_relationship">attach_relationship</a></li>

      <li ><a href="#method-i-collect_related_objects">collect_related_objects</a></li>

      <li ><a href="#method-i-load_relationships">load_relationships</a></li>

      <li ><a href="#method-i-related_objects">related_objects</a></li>

      <li ><a href="#method-i-store_relationship">store_relationship</a></li>

    </ul>
  </div>



  <footer id="validator-badges" role="contentinfo">
  <p><a href="https://validator.w3.org/check/referer">Validate</a></p>
  <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.15.1.</p>
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>
</footer>

</nav>

<main role="main" aria-labelledby="module-RubyXL::RelationshipSupport">
  
  
    <ol role="navigation" aria-label="Breadcrumb navigation" class="breadcrumb">
      
      <li>
        
        <a href="../RubyXL.html">RubyXL</a><span>::</span>
        
      </li>
      
      <li>
        
        <span>RelationshipSupport</span>
        
      </li>
      
    </ol>
  

  <h1 id="module-RubyXL::RelationshipSupport" class="anchor-link module">
    module RubyXL::RelationshipSupport
  </h1>

  <section class="description">
    
<p><a href="RelationshipSupport.html"><code>RelationshipSupport</code></a> module enables automatic loading and saving of _rels for the respective file</p>

  </section>


  <section id="5Buntitled-5D" class="documentation-section anchor-link">







    <section class="attribute-method-details method-section">
      <header>
        <h3>Attributes</h3>
      </header>


      <div id="attribute-i-generic_storage" class="method-detail anchor-link">
        <div class="method-heading attribute-method-heading">
          <a href="#attribute-i-generic_storage" title="Link to this attribute">
            <span class="method-name">generic_storage</span>
            <span class="attribute-access-type">[RW]</span>
          </a>
        </div>

        <div class="method-description">


        

        </div>
      </div>

      <div id="attribute-i-relationship_container" class="method-detail anchor-link">
        <div class="method-heading attribute-method-heading">
          <a href="#attribute-i-relationship_container" title="Link to this attribute">
            <span class="method-name">relationship_container</span>
            <span class="attribute-access-type">[RW]</span>
          </a>
        </div>

        <div class="method-description">


        

        </div>
      </div>

    </section>



     <section id="public-class-5Buntitled-5D-method-details" class="method-section anchor-link">
       <header>
         <h3>Public Class Methods</h3>
       </header>


      <div id="method-c-included" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-c-included" title="Link to this method">
                <span class="method-name">included</span>
                <span class="method-args">(klass)</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="included-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/relationships.rb, line 144</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">included</span>(<span class="ruby-identifier">klass</span>)
  <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">class_variable_set</span>(<span class="ruby-value">:@@ooxml_relationships</span>, {})
  <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">extend</span> <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">RelationshipSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">ClassMehods</span>
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


    </section>

     <section id="public-instance-5Buntitled-5D-method-details" class="method-section anchor-link">
       <header>
         <h3>Public Instance Methods</h3>
       </header>


      <div id="method-i-attach_relationship" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-attach_relationship" title="Link to this method">
                <span class="method-name">attach_relationship</span>
                <span class="method-args">(rid, rf)</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="attach_relationship-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/relationships.rb, line 184</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">attach_relationship</span>(<span class="ruby-identifier">rid</span>, <span class="ruby-identifier">rf</span>)
  <span class="ruby-identifier">relationships</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">class_variable_get</span>(<span class="ruby-value">:@@ooxml_relationships</span>)
  <span class="ruby-identifier">klass</span> = <span class="ruby-identifier">rf</span>.<span class="ruby-identifier">class</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">relationships</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">klass</span>) <span class="ruby-keyword">then</span>
    <span class="ruby-identifier">accessor</span> = <span class="ruby-identifier">relationships</span>[<span class="ruby-identifier">klass</span>]
    <span class="ruby-keyword">case</span> <span class="ruby-identifier">accessor</span>
    <span class="ruby-keyword">when</span> <span class="ruby-constant">NilClass</span> <span class="ruby-keyword">then</span>
      <span class="ruby-comment"># Relationship is known, but we don&#39;t have a special accessor for it, store as generic</span>
      <span class="ruby-identifier">store_relationship</span>(<span class="ruby-identifier">rf</span>)
    <span class="ruby-keyword">when</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">then</span>
      <span class="ruby-comment"># Do nothing, the code will perform attaching on its own</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">container</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">accessor</span>)
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">container</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-keyword">then</span> <span class="ruby-identifier">container</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">rf</span>
      <span class="ruby-keyword">else</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{accessor}=&quot;</span>, <span class="ruby-identifier">rf</span>)
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span> <span class="ruby-identifier">store_relationship</span>(<span class="ruby-identifier">rf</span>, <span class="ruby-value">:unknown</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


      <div id="method-i-collect_related_objects" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-collect_related_objects" title="Link to this method">
                <span class="method-name">collect_related_objects</span>
                <span class="method-args">()</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="collect_related_objects-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/relationships.rb, line 155</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">collect_related_objects</span>
  <span class="ruby-identifier">res</span> = <span class="ruby-identifier">related_objects</span>.<span class="ruby-identifier">compact</span> <span class="ruby-comment"># Avoid tainting +related_objects+ array</span>
  <span class="ruby-identifier">res</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">generic_storage</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">generic_storage</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">relationship_container</span> <span class="ruby-keyword">then</span>
    <span class="ruby-identifier">relationship_container</span>.<span class="ruby-identifier">owner</span> = <span class="ruby-keyword">self</span>
    <span class="ruby-identifier">res</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">relationship_container</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">related</span> = []

  <span class="ruby-identifier">res</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:empty?</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">empty?</span>
    <span class="ruby-identifier">related</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">obj</span>
    <span class="ruby-identifier">related</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">collect_related_objects</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:collect_related_objects</span>)
  }

  <span class="ruby-identifier">related</span>
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


      <div id="method-i-load_relationships" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-load_relationships" title="Link to this method">
                <span class="method-name">load_relationships</span>
                <span class="method-args">(dir_path, base_file_name)</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="load_relationships-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/relationships.rb, line 175</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">load_relationships</span>(<span class="ruby-identifier">dir_path</span>, <span class="ruby-identifier">base_file_name</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">relationship_container</span> = <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">OOXMLRelationshipsFile</span>.<span class="ruby-identifier">load_relationship_file</span>(<span class="ruby-identifier">dir_path</span>, <span class="ruby-identifier">base_file_name</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">relationship_container</span>.<span class="ruby-identifier">nil?</span>

  <span class="ruby-identifier">relationship_container</span>.<span class="ruby-identifier">load_related_files</span>(<span class="ruby-identifier">dir_path</span>, <span class="ruby-identifier">base_file_name</span>).<span class="ruby-identifier">each_pair</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">rid</span>, <span class="ruby-identifier">related_file</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">attach_relationship</span>(<span class="ruby-identifier">rid</span>, <span class="ruby-identifier">related_file</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">related_file</span>
  }
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


      <div id="method-i-related_objects" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-related_objects" title="Link to this method">
                <span class="method-name">related_objects</span>
                <span class="method-args">()</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="related_objects-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/relationships.rb, line 151</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">related_objects</span> <span class="ruby-comment"># Override this method</span>
  []
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


      <div id="method-i-store_relationship" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-store_relationship" title="Link to this method">
                <span class="method-name">store_relationship</span>
                <span class="method-args">(related_file, unknown = false)</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="store_relationship-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/relationships.rb, line 205</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">store_relationship</span>(<span class="ruby-identifier">related_file</span>, <span class="ruby-identifier">unknown</span> = <span class="ruby-keyword">false</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">generic_storage</span> <span class="ruby-operator">||=</span> []
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">unknown</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-constant">RubyXL</span>.<span class="ruby-identifier">class_variable_get</span>(<span class="ruby-value">:@@suppress_warnings</span>) <span class="ruby-keyword">then</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;WARNING: #{self.class} is not aware how to process #{related_file.class}&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">generic_storage</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">related_file</span>
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


    </section>

  </section>

</main>
</body>

